using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using Model;
using Model.WWW_WWW.Rss;
using IProvider.Config;


namespace IProvider.Interface
{
    public abstract class IRssProvider : DataAccess
    {
        private static object obj = new object();
        private static IRssProvider instance;
        public static IRssProvider Instance
        {
            get
            {
                lock (obj)
                {
                    if (instance == null)
                    {
                        instance = (IRssProvider)Activator.CreateInstance(Common.GetTypeFromAssembly(WWW_WWW_Rss_Config.AssemblyName, WWW_WWW_Rss_Config.DbProviderType));
                    }
                }
                return instance;
            }
        }

        #region
        public abstract List<T_RssFeedSubscriptionDetails> T_RssFeedSubscriptionSelect();
        public abstract List<T_RssFeedSubscriptionDetails> T_RssFeedSubscriptionSelect(string whereCause, string sortExpression, int pageIndex, int pageSize, out int recordCount);
        public abstract DataTable T_RssFeedSubscriptionSelect(string memberNo);
        public abstract string GetLanguage(string memberno);
        public abstract int T_RssFeedSubscriptionUpdate(string memberNo, string url, int showCount);
        public abstract int T_RssFeedSubscriptionDelete(string memberNo, string url);
        public abstract T_RssFeedSubscriptionDetails T_RssFeedSubscriptionSelectByPK(T_RssFeedSubscriptionDetails entity);
        public abstract int T_RssFeedSubscriptionDelete(T_RssFeedSubscriptionDetails entity);
        public abstract int T_RssFeedSubscriptionUpdate(T_RssFeedSubscriptionDetails entity);
        public abstract int T_RssFeedSubscriptionInsert(T_RssFeedSubscriptionDetails entity);
        #endregion

        #region
        public abstract List<T_RssFeedSubscriptionDetails> T_RssFeedSubscriptionSelect(IDbConnection cn, IDbTransaction trans);
        public abstract List<T_RssFeedSubscriptionDetails> T_RssFeedSubscriptionSelect(IDbConnection cn, IDbTransaction trans, string whereCause, string sortExpression, int pageIndex, int pageSize, out int recordCount);
        public abstract T_RssFeedSubscriptionDetails T_RssFeedSubscriptionSelectByPK(IDbConnection cn, IDbTransaction trans, T_RssFeedSubscriptionDetails entity);
        public abstract int T_RssFeedSubscriptionDelete(IDbConnection cn, IDbTransaction trans, T_RssFeedSubscriptionDetails entity);
        public abstract int T_RssFeedSubscriptionUpdate(IDbConnection cn, IDbTransaction trans, T_RssFeedSubscriptionDetails entity);
        public abstract int T_RssFeedSubscriptionInsert(IDbConnection cn, IDbTransaction trans, T_RssFeedSubscriptionDetails entity);
        #endregion

        #region
        protected virtual T_RssFeedSubscriptionDetails T_RssFeedSubscriptionGetEntityFromReader(IDataReader reader)
        {
            return new T_RssFeedSubscriptionDetails(
            (reader["MemberNo"] == DBNull.Value ? "" : (String)reader["MemberNo"]),
             (reader["RSSURL"] == DBNull.Value ? "" : (String)reader["RSSURL"]),
             (reader["SortID"] == DBNull.Value ? "" : (String)reader["SortID"]),
             (reader["ShowCount"] == DBNull.Value ? 0 : (Int32)reader["ShowCount"]),
             (reader["Comment"] == DBNull.Value ? "" : (String)reader["Comment"])
                );
        }

        protected virtual List<T_RssFeedSubscriptionDetails> T_RssFeedSubscriptionGetEntityCollectionFromReader(IDataReader reader)
        {
            List<T_RssFeedSubscriptionDetails> entities = new List<T_RssFeedSubscriptionDetails>();
            while (reader.Read())
                entities.Add(T_RssFeedSubscriptionGetEntityFromReader(reader));
            return entities;
        }

        #endregion

        #region
        public abstract List<T_RssFeedDetails> T_RssFeedSelect();
        public abstract List<T_RssFeedDetails> T_RssFeedSelect(string whereCause, string sortExpression, int pageIndex, int pageSize, out int recordCount);
        public abstract T_RssFeedDetails T_RssFeedSelectByPK(T_RssFeedDetails entity);
        public abstract int T_RssFeedDelete(T_RssFeedDetails entity);
        public abstract int T_RssFeedUpdate(T_RssFeedDetails entity);
        public abstract int T_RssFeedInsert(T_RssFeedDetails entity);
        #endregion

        #region
        public abstract List<T_RssFeedDetails> T_RssFeedSelect(IDbConnection cn, IDbTransaction trans);
        public abstract List<T_RssFeedDetails> T_RssFeedSelect(IDbConnection cn, IDbTransaction trans, string whereCause, string sortExpression, int pageIndex, int pageSize, out int recordCount);
        public abstract T_RssFeedDetails T_RssFeedSelectByPK(IDbConnection cn, IDbTransaction trans, T_RssFeedDetails entity);
        public abstract int T_RssFeedDelete(IDbConnection cn, IDbTransaction trans, T_RssFeedDetails entity);
        public abstract int T_RssFeedUpdate(IDbConnection cn, IDbTransaction trans, T_RssFeedDetails entity);
        public abstract int T_RssFeedInsert(IDbConnection cn, IDbTransaction trans, T_RssFeedDetails entity);
        #endregion

        #region
        protected virtual T_RssFeedDetails T_RssFeedGetEntityFromReader(IDataReader reader)
        {
            return new T_RssFeedDetails(
            (reader["ID"] == DBNull.Value ? 0 : (Int32)reader["ID"]),
             (reader["RSSURL"] == DBNull.Value ? "" : (String)reader["RSSURL"]),
             (reader["LanguageLearn"] == DBNull.Value ? "" : (String)reader["LanguageLearn"]),
             (reader["LanguageSpeak"] == DBNull.Value ? "" : (String)reader["LanguageSpeak"]),
             (reader["Description"] == DBNull.Value ? "" : (String)reader["Description"]),
             (reader["Recommend"] == DBNull.Value ? false : (Boolean)reader["Recommend"]),
             (reader["CatID"] == DBNull.Value ? 0 : (Int32)reader["CatID"]),
             (reader["Active"] == DBNull.Value ? false : (Boolean)reader["Active"]),
             (reader["Source"] == DBNull.Value ? "" : (String)reader["Source"]),
             (reader["UserCount"] == DBNull.Value ? 0 : (Int32)reader["UserCount"])
                );
        }

        protected virtual List<T_RssFeedDetails> T_RssFeedGetEntityCollectionFromReader(IDataReader reader)
        {
            List<T_RssFeedDetails> entities = new List<T_RssFeedDetails>();
            while (reader.Read())
                entities.Add(T_RssFeedGetEntityFromReader(reader));
            return entities;
        }
        #endregion
    }
}
